//调整尺寸
function changePanelSize() {
  /*$(".mediaPanel").css("left",mediaLeft);
       
    $(".mediaPanel").css("top",mediaTop); */

  $(".mediaPanel").css("width", mediaPanelWidth);

  $(".mediaPanel").css("height", mediaPanelHeight);

  $("#video1").css("width", mediaPanelWidth);

  $("#video1").css("height", mediaPanelHeight);

  $("#loadingMask").css("width", mediaPanelWidth);

  $("#loadingMask").css("height", mediaPanelHeight);

  $("#loadingImg").css("left", mediaPanelWidth / 2 - 90);

  $("#loadingImg").css("top", mediaPanelHeight / 2 - 90);
}

//设置课程标题
function setInitTitle() {
  var title = "";

  if (title != "") {
    if (title.length >= 23) {
      $(".titlePanel").css("font-size", 20 + "px");

      if (title.length >= 45) {
        $(".titlePanel").css("font-size", 16 + "px");
      }
    }

    $(".titlePanel").html(title);
  }
}

//下载文字资料
function downLoadTxt() {
  var path = MEDIA_URL_PRE + getQueryValue("filename") + "/001.jpg";

  ////var path = "001.jpg";

  $.ajax({
    type: "get",

    url: path,

    success: function () {
      hasPoster = true;

      posterURL = path;

      initPlayer();
    },
    error: function () {
      hasPoster = false;

      posterURL = "";

      initPlayer();
    },
  });
}

//获取地址栏参数
function getQueryValue(queryName) {
  var query = decodeURI(window.location.search.substring(1));

  var vars = query.split("&");

  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");

    if (pair[0] == queryName) {
      return pair[1];
    }
  }

  return null;
}

//获取视频地址
function setVideoPath() {
  var path = "";

  if (VIDEO_PATH != "") path = VIDEO_PATH;

  // path=  course_list[currentCourseIndex].course_url;

  // console.log("path"+path);

  // path = MEDIA_URL_PRE + getQueryValue("filename") + "/contents/video_mp4/1.mp4";

  /* path = "1.mp4"; */

  if (path != "") {
    return path;
  } else {
    return false;
  }
}

//获取URL地址
function get_media_path() {
  var sRet = parent.window.location.href;

  var nPos = sRet.lastIndexOf("/");

  sRet = sRet.substring(0, nPos);

  return sRet;
}

//获取关键词信息
function getKeyWords() {
  var innerText = "";

  if (hasKeyWords) {
    innerText = $("#INTRO", parent.document).html();

    $("#maskTexts").html(innerText);
  }
}

//时间格式化1
function getTimeEmt(ms) {
  var s;

  var m = parseInt(ms / 60);

  s = parseInt(ms - m * 60);

  var h;

  h = parseInt(m / 60);

  m -= h * 60;

  return make2Str(h) + ":" + make2Str(m) + ":" + make2Str(s);
}

//时间格式化2
function make2Str(i) {
  if (i < 10) return "0" + i.toString();
  else return i.toString();
}

$(function () {
  //长时间挂机暂停(默认关闭)
  $(document).mousemove(function () {
    if (autoStop) {
      clearTimeout(auto_stop_timer);

      auto_stop_timer = setTimeout(onAutoStopFunction, AUTO_STOP_TIME);
    } else {
    }
  });

  $(document).on("visibilitychange", function (e) {
    if (e.target.visibilityState === "visible") {
    } else if (e.target.visibilityState === "hidden") {
      if (autoStop) {
        clearTimeout(auto_stop_timer);

        setVideoPause();
      }
    }
  });

  $("#playButton").click(function () {
    setVideoPlay();
  });

  $("#pauseButton").click(function () {
    setVideoPause();
  });

  $("#adClose").click(function () {
    closeAdArea();
  });

  $("#adImage").click(function () {
    openAdHref();
  });

  $("#nextChapter").click(function () {
    changeURL();
  });

  $("#muteButton").click(function () {
    $(this).hide();

    $("#soundButton").show();

    $("#soundBall").css("top", "75px");

    changeSound(0);
  });

  $("#soundButton").click(function () {
    $(this).hide();

    $("#muteButton").show();

    $("#soundBall").css("top", "38px");

    changeSound(0.5);
  });

  $("#videoFull").click(function () {
    videoFull();
  });

  $("#maskCloseButton").click(function () {
    closeMask();
  });

  $("#playRate").click(function () {
    showPlayRatePanel();
  });

  $("#playRateList li").click(function () {
    var id = $(this).attr("id").substring(8, 9);

    var currentSelectObj = $("#playRate" + CURRENT_RATE_INDEX);

    currentSelectObj.removeClass("listSelected");

    $(this).addClass("listSelected");

    CURRENT_RATE_INDEX = id;

    $("#playRate").html(rate_list[parseInt(id)] + "X");

    changeVideoPlayRate(rate_list[parseInt(id)]);
  });

  loadPage();

  downLoadTxt();

  getKeyWords();
});
